﻿using System;
using System.Windows.Forms;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using VerticalMenu.Utility;

namespace VerticalMenu.Commands
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class ExternalCommandHidePage : IExternalCommand, IExternalCommandAvailability
	{
		public virtual Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			try
			{
				int num = Convert.ToInt32(commandData.Application.Application.VersionNumber);
				if (num < 2015)
				{
					MessageBox.Show("此功能只在Revit2015及其以上版本可用", "盈建科提示");
					return Autodesk.Revit.UI.Result.Succeeded;
				}
				VerticalMenuApplication.m_ThisApp.SetWindowVisibility(commandData, false);
				StateController.SaveState(StateController.StateEnum.SE_Hide);
			}
			catch (InvalidOperationException ex)
			{
				MessageBox.Show(ex.Message, "盈建科提示");
			}
			catch (Exception)
			{
				MessageBox.Show("竖向菜单未完成注册", "盈建科提示");
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
		{
			return applicationData.ActiveUIDocument != null;
		}
	}
}
